package cn.cvzhanshi.wechatpush.config;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;

public class BabyDidi {
    public static void main(String[] args) throws WxErrorException {
        BabyDidi.Di();
    }
    private static String appId = "";//填写微信公众号接口测试账号的id
    private static String secret = "";//密码
    public static void Di() throws WxErrorException {
        WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
        wxStorage.setAppId(appId);
        wxStorage.setSecret(secret);
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxStorage);
        WxMpTemplateMessage templateMessage2 = WxMpTemplateMessage.builder()
                .toUser("")//发送用户的微信id
                .templateId("Nbm2cPoiu8GwXCnl5_yudrw6lufY4k6MDLcIICxdzaQ")//发送的模板id
                .build();
        String str = "还在收拾衣服蛮？注意休息噢！";
        templateMessage2.addData(new WxMpTemplateData("str",str,"#de3f7c"));
        System.out.println(templateMessage2.toJson());
        wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage2);//发送
    }
}
